﻿Imports System.Text.RegularExpressions
Imports DAL
Imports System.Linq
Imports System.Drawing.Drawing2D

REM detecter modification TEL

Public Class UCGestionEmployeV2
    Public prog As Boolean
    Dim employe As Employe
    Dim empconge As New List(Of Conge)
    Dim inter As New UCEmployeIntervenant
    Dim bure As New UCEmployeBureau
    Dim stage As New UCEmployeStagiaire
    Dim conge As New List(Of Conge)
    Dim listeConge As New List(Of DAL.Conge)
    Dim listeTel As New List(Of DAL.Telephone)
    Dim listeDispo As New List(Of DAL.Disponibilite)
    Dim listeFormation As New List(Of DAL.EmployeFormation)
    Dim listeAffinite As New List(Of DAL.EmployeAffinite)
    Public mode As Mode = 1
    Public Event listeEmp As EventHandler
    Public Event suppression As EventHandler
    Public Event modification As EventHandler
    Public Event annulation As eventhandler

    Private Sub UCGestionEmployeV2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        employe = New Employe
        CboPoste.SelectedIndex = 3
        CboBeneficiaires.SelectedIndex = 0
        CboEmployes.SelectedIndex = 0
        CboHoraires.SelectedIndex = 0
        If Not Me.DesignMode Then

            Dim listVille As New List(Of Ville)
            For Each Ville In bd.Villes
                listVille.Add(Ville)
            Next
            CboVille.DataSource = listVille
            CboVille.DisplayMember = "Nom"
            CboVille.ValueMember = "ID"
            CboInterets.DataSource = From x In bd.Affinites Select x
            CboInterets.DisplayMember = "Nom"
            CboInterets.ValueMember = "ID"
            Dim listeForm As New List(Of Formation)
            For Each form In bd.Formations
                listeForm.Add(form)
            Next
            CBFormation.DataSource = listeForm
            CBFormation.DisplayMember = "Nom"
            CBFormation.ValueMember = "ID"
        End If

        CboVille.SelectedIndex = 0
        AddHandler UcTelephone1.modification, AddressOf detecterChangement
        AddHandler inter.Modification, AddressOf detecterChangement
        AddHandler bure.Modification, AddressOf detecterChangement
        AddHandler stage.Modification, AddressOf detecterChangement
        ToggleEditionConge(0)
    End Sub

    Public Sub Ajouter_Employe(ByVal sender As Object, ByVal e As System.EventArgs)
        Select Case mode
            Case mode.ajout
                ViderChamps()
            Case mode.consultation
                employe = New Employe
                ViderChamps()
                changerMode(mode.ajout)
            Case mode.edition
                If MsgBox("Voulez-vous enregistrer les modifications de l'employé?", MsgBoxStyle.YesNo) = 6 Then
                    Sauver_Employe(Nothing, Nothing)
                End If
                employe = New Employe
                ViderChamps()
                changerMode(mode.ajout)
        End Select
    End Sub

    Public Sub Enlever_Employe(ByVal sender As Object, ByVal e As System.EventArgs)
        Select Case mode
            Case mode.consultation
                If Not employe.ID = empConnecte.id Then
                    If MessageBox.Show("Êtes-vous sûr de vouloir supprimer l'employé?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
                        employe.Supprime = True
                        employe.SupprimeDate = Now
                        bd.SubmitChanges()
                        ViderChamps()
                        RaiseEvent listeEmp("Rafraichir", Nothing)
                        changerMode(mode.consultation)
                    Else
                        Return
                    End If
                Else
                    MsgBox("Il est impossible de supprimer sa fiche d'employé", vbCritical)
                End If
            Case mode.edition
                If Not employe.ID = empConnecte.id Then
                    If MessageBox.Show("Êtes-vous sûr de vouloir supprimer l'employé?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
                        employe.Supprime = True
                        employe.SupprimeDate = Now
                        bd.SubmitChanges()
                        ViderChamps()
                        RaiseEvent listeEmp("Rafraichir", Nothing)
                        changerMode(mode.consultation)
                    End If
                Else
                    MsgBox("Il est impossible de supprimer sa fiche s'employé", vbCritical)
                End If
        End Select

    End Sub

    Public Sub Annuler_Employe(ByVal sender As Object, ByVal e As System.EventArgs)
        inter.ViderChamps()
        bure.ViderChamps()
        stage.ViderChamps()
        'bd.Refresh(Data.Linq.RefreshMode.OverwriteCurrentValues, bd.Employes)
        bd.Refresh(Data.Linq.RefreshMode.OverwriteCurrentValues, bd.Telephones)
        bd.Refresh(Data.Linq.RefreshMode.OverwriteCurrentValues, bd.Conges)
        Select Case mode
            Case mode.ajout
                ViderChamps()
            Case mode.edition
                afficherEmploye()
                changerMode(mode.consultation)

        End Select
        RaiseEvent modification(False, Nothing)
        RaiseEvent annulation(False, Nothing)
    End Sub

    Public Sub Sauver_Employe(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Validation() Then
            MsgBox("Certains champs contiennent des erreurs. Veuillez les corriger pour continuer")
            Exit Sub
        Else
            Dim emp As Employe
            If mode = mode.ajout Then
                emp = New Employe()
                bd.Employes.InsertOnSubmit(emp)
            Else
                emp = (From x In bd.Employes Where x.ID = employe.ID Select x).First
            End If


            With emp
                .Nom = StrConv(TxtNom.Text.Trim, VbStrConv.ProperCase)
                .Prenom = StrConv(TxtPrenom.Text.Trim, VbStrConv.ProperCase)
                .NAS = TxtNAS.Text
                .Poste = CboPoste.SelectedIndex

                .DateNaissance = DtpDateNaissance.Value
                .Adresse = TxtAdresse.Text
                .Ville = CboVille.SelectedValue
                .CodePostal = TxtCodePostal.Text
                .Courriel = TxtCourriel.Text
                .Note = TxtNotes.Text

                If Not ImgEmploye.BackgroundImage Is Nothing Then
                    Dim flux As New IO.MemoryStream
                    ImgEmploye.BackgroundImage.Save(flux, System.Drawing.Imaging.ImageFormat.Png)
                    .Photo = flux.ToArray
                End If

                .Login = TxtUtilsateur.Text
                If TxtMotdePasse.Text <> String.Empty Then
                    .Password = SimpleCrypt(TxtMotdePasse.Text)
                End If

                .GestionBeneficiaire = CboBeneficiaires.SelectedIndex
                .GestionEmploye = CboEmployes.SelectedIndex
                .GestionHoraire = CboHoraires.SelectedIndex
                .DateEmbauche = DtpDebut.Value
                .DateFin = IIf(DtpFin.Checked, DtpFin.Value, Nothing)
                If empConnecte.id = employe.ID Then
                    empConnecte.gestionBeneficiaire = .GestionBeneficiaire
                    empConnecte.gestionEmploye = .GestionEmploye
                    empConnecte.gestionHoraire = .GestionHoraire
                    FrmAcceuil.Frm_Acceuil_Show(Nothing, Nothing)
                End If
                Dim formationEmp As New System.Data.Linq.EntitySet(Of EmployeFormation)
                formationEmp.AddRange(listeFormation)
                .EmployeFormations = formationEmp

                Dim telephoneEmp As New System.Data.Linq.EntitySet(Of Telephone)
                telephoneEmp.AddRange(UcTelephone1.GetTelephones())
                .Telephones = telephoneEmp

                Dim affiniteEmp As New System.Data.Linq.EntitySet(Of EmployeAffinite)
                affiniteEmp.AddRange(listeAffinite)
                .EmployeAffinites = affiniteEmp

                Dim congeEmp As New System.Data.Linq.EntitySet(Of DAL.Conge)
                congeEmp.AddRange(listeConge)
                .Conges = congeEmp
            End With

            bd.SubmitChanges()

            Select Case CboPoste.SelectedIndex
                Case 0
                    If Not (From x In bd.Intervenants Where x.IDEmploye = emp.ID Select x).Count > 0 Then
                        If (From x In bd.EmployeBureaus Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.EmployeBureaus.DeleteOnSubmit((From x In bd.EmployeBureaus Where x.IDEmploye = emp.ID Select x).First)
                        If (From x In bd.Stagiaires Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.Stagiaires.DeleteOnSubmit((From x In bd.Stagiaires Where x.IDEmploye = emp.ID Select x).First)
                        inter.Sauver_Employe(mode.ajout, emp)
                    Else
                        inter.Sauver_Employe(mode.edition, emp)
                    End If
                Case 1

                    If Not (From x In bd.EmployeBureaus Where x.IDEmploye = emp.ID Select x).Count > 0 Then
                        If (From x In bd.Intervenants Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.Intervenants.DeleteOnSubmit((From x In bd.Intervenants Where x.IDEmploye = emp.ID Select x).First)
                        If (From x In bd.Stagiaires Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.Stagiaires.DeleteOnSubmit((From x In bd.Stagiaires Where x.IDEmploye = emp.ID Select x).First)
                        bure.Sauver_Employe(mode.ajout, emp)
                    Else
                        bure.Sauver_Employe(mode.edition, emp)
                    End If
                Case 2
                    If Not (From x In bd.Stagiaires Where x.IDEmploye = emp.ID Select x).Count > 0 Then
                        If (From x In bd.Intervenants Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.Intervenants.DeleteOnSubmit((From x In bd.Intervenants Where x.IDEmploye = emp.ID Select x).First)
                        If (From x In bd.EmployeBureaus Where x.IDEmploye = emp.ID Select x).Count > 0 Then bd.EmployeBureaus.DeleteOnSubmit((From x In bd.EmployeBureaus Where x.IDEmploye = emp.ID Select x).First)
                        stage.Sauver_Employe(mode.ajout, emp)
                    Else
                        stage.Sauver_Employe(mode.edition, emp)
                    End If
            End Select
            changerMode(mode.consultation)
            RaiseEvent listeEmp("Rafraichir", Nothing)
            RaiseEvent listeEmp(emp.ID, Nothing)
            RaiseEvent modification("false", Nothing)
        End If

    End Sub

    'fonction qui valide les informations avant de les envoyés à la BD
    Public Function Validation()
        Dim verif As Boolean = True
        ErrVal.Clear()

        'Vérification des date de début et fin d'embauche
        If (DtpFin.Checked AndAlso DtpFin.Value.DayOfYear < DtpDebut.Value.DayOfYear) Then
            ErrVal.SetError(DtpFin, "La date de fin ne peut pas être inférieure à la date d'embauche")
            ErrVal.SetError(DtpDebut, "La date de fin ne peut pas être inférieure à la date d'embauche")
            verif = False
        End If

        'Vérification des date de début et fin de congé

        'If (DtpJourFin.Value.Date < DtpJourDebut.Value.Date) Then
        '    ErrVal.SetError(DtpJourDebut, "La date de fin doit être ultérieur à la date de début")
        '    ErrVal.SetError(DtpJourFin, "La date de fin doit être ultérieur à la date de début")
        'End If

        'vérification du nom vide
        If (TxtNom.Text = "") Then
            ErrVal.SetError(TxtNom, "Veuillez entrer un nom")
            verif = False
        End If

        'vérification du nom d'utilisateur vide
        'If (TxtUtilsateur.Text = "") Then
        '    ErrVal.SetError(TxtUtilsateur, "Veuillez entrer un nom d'utilisateur")
        '    verif = False
        'Else
        '    ErrVal.SetError(TxtUtilsateur, "")
        'End If

        'vérification du mot de passe vide
        'If (TxtMotdePasse.Text = "") Then
        '    ErrVal.SetError(TxtMotdePasse, "Veuillez entrer un mot de passe")
        '    verif = False
        'Else
        '    ErrVal.SetError(TxtMotdePasse, "")
        'End If

        'vérification du prénom vide
        If (TxtPrenom.Text = "") Then
            ErrVal.SetError(TxtPrenom, "Veuillez entrer un prénom")
            verif = False
        End If
        TxtNAS.Text = TxtNAS.Text.Replace(" ", "")
        If Not TxtNAS.Text = String.Empty Then
            If TxtNAS.TextLength < 9 Then
                ErrVal.SetError(TxtNAS, "Le nas doit contenir 9 chiffres")
                verif = False
            Else
                If IsNumeric(TxtNAS.Text) Then
                    Dim val1 As Integer
                    Dim val2 As Integer
                    For ctr As Integer = 0 To 8 Step 1
                        If ctr Mod 2 = 0 Then
                            val1 += Conversion.Val(TxtNAS.Text(ctr))
                        Else
                            val2 = Conversion.Val(TxtNAS.Text(ctr))
                            val2 *= 2
                            If val2 > 9 Then
                                val2 -= 9
                            End If
                            val1 += val2
                        End If
                    Next
                    If Not (val1 Mod 10 = 0) Then
                        ErrVal.SetError(TxtNAS, "Le nas est invalide")
                        verif = False
                    Else
                        TxtNAS.Text = TxtNAS.Text.Substring(0, 3) + " " + TxtNAS.Text.Substring(3, 3) + " " + TxtNAS.Text.Substring(6, 3)
                    End If
                Else
                    ErrVal.SetError(TxtNAS, "Le nas doit être numérique")
                    verif = False
                End If
            End If
        End If
        If DtpDateNaissance.Value > Today Then
            ErrVal.SetError(DtpDateNaissance, "La date doit être inférieure à la journée actuelle")
            verif = False
            'Validation de l'insertion d'un bénéficiaire de plus de 119 ans
        ElseIf DtpDateNaissance.Value.Year < Today.Year - 120 AndAlso MsgBox("Êtes-vous sûr d'avoir un bénéficiaire de plus de 119 ans?", vbYesNo) = vbNo Then
            DtpDateNaissance.Value = Today
            verif = False
        End If

        If TxtUtilsateur.Text <> String.Empty AndAlso (From emp In bd.Employes Where emp.Login = TxtUtilsateur.Text And emp.ID <> employe.ID).Count > 0 Then
            ErrVal.SetError(TxtUtilsateur, "Nom d'utilisateur déjà utilisé")
            verif = False
        End If
        'Si aucune erreur, ajout ou modification des infomations de l'employé
        If verif = True Then

            Return True
        Else
            Return False
        End If
    End Function

    'Fonction permettant de valider les Adresses entrés
    'Private Function verifAdresse(ByVal test)
    '    Dim re As Regex = New Regex("^([\d]+)([\s])(.+)$")
    '    Return re.IsMatch(test)
    'End Function

    'Fonction permettant de valider le code postal entré
    'Private Function VerifCP(ByVal test)
    '    Dim re As Regex = New Regex("^([^DdFfIiOoQqUuWwZz0-9\W])([0-9])([^DdFfIiOoQqUu0-9\W])\s([0-9])([^DdFfIiOoQqUu0-9\W])([0-9])$")
    '    Return re.IsMatch(test)
    'End Function

    'Validation du format de code postal
    'Private Sub MTBCodePostal_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCodePostal.Leave
    '    If Not VerifCP(sender.Text) And Not sender.text = "" Then
    '        ErrVal.SetError(sender, "Le code postal est invalide")
    '    Else
    '        ErrVal.SetError(sender, "")
    '    End If
    'End Sub

    'Validation de la date de naissance
    'Private Sub DtpDateNaissance_Validating(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DtpDateNaissance.Validating
    '    If sender.Value > Today Then
    '        ErrVal.SetError(sender, "La date doit être inférieure à la journée actuelle")
    '        'Validation de l'insertion d'un employé de plus de 119 ans
    '    ElseIf sender.value.year < Today.Year - 120 Then
    '        ErrVal.SetError(sender, "")
    '        MsgBox("Êtes-vous sur d'avoir un employé de plus de 119 ans?", vbYesNo)
    '        If MsgBoxResult.No Then
    '            sender.Value = Today
    '        End If
    '    End If
    'End Sub

    'Validation du format de l'adresse
    'Private Sub TxtAdresse_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtAdresse.Leave
    '    If Not verifAdresse(sender.text) And Not sender.Text = "" Then
    '        ErrVal.SetError(sender, "L'adresse est invalide")
    '    Else
    '        ErrVal.SetError(sender, "")
    '    End If
    'End Sub

    'Validation du nas.
    'Private Sub TxtNAS_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNAS.Leave
    '    If TxtNAS.TextLength < 9 Then
    '        ErrVal.SetError(sender, "Le nas doit contenir 9 chiffres")
    '    ElseIf Not (TxtNAS.TextLength = 9 Or (TxtNAS.Text(3) = " " And TxtNAS.Text(7) = " " And TxtNAS.TextLength = 11)) Then
    '        ErrVal.SetError(sender, "Le format est de 9 chiffre consécutif ou séparer avec un espaces au trois chiffres")
    '    Else
    '        Dim nas As String = ""
    '        If TxtNAS.TextLength = 9 Then
    '            nas = TxtNAS.Text
    '        Else
    '            For ctr As Integer = 0 To 10 Step 1
    '                If Not (ctr = 3 Or ctr = 7) Then
    '                    nas += TxtNAS.Text(ctr)
    '                End If
    '            Next
    '        End If
    '        ErrVal.SetError(sender, "")
    '        If IsNumeric(nas) Then
    '            Dim val1 As Integer
    '            Dim val2 As Integer
    '            For ctr As Integer = 0 To 8 Step 1
    '                If ctr Mod 2 = 0 Then
    '                    val1 += Conversion.Val(nas(ctr))
    '                Else
    '                    val2 = Conversion.Val(nas(ctr))
    '                    val2 *= 2
    '                    If val2 > 9 Then
    '                        val2 -= 9
    '                    End If
    '                    val1 += val2
    '                End If
    '            Next
    '            If Not (val1 Mod 10 = 0) Then
    '                ErrVal.SetError(sender, "Le nas est invalide")
    '            Else
    '                ErrVal.SetError(sender, "")
    '            End If
    '        Else
    '            ErrVal.SetError(sender, "Le nas doit être numérique")
    '        End If
    '    End If
    'End Sub

    'Permet la navigation entre les onglets
    Private Sub GestionOnglets(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTelephone.Click, BtnInfoConnection.Click, BtnIntervenant.Click, BtnDispo.Click, BtnConge.Click, LblInteret.Click, BtnSupp.Click
        sender.imageINdex = IIf(sender.ImageIndex = 1, 0, 1)
        Select Case True
            Case sender.Name.Substring(3) = "Telephone"
                UcTelephone1.Visible = Not UcTelephone1.Visible

            Case sender.Name.Substring(3) = "InfoConnection"
                TLPInfoConnection.Visible = Not TLPInfoConnection.Visible

            Case sender.Name.Substring(3) = "Intervenant"
                TLPDetailIntervenant.Visible = Not TLPDetailIntervenant.Visible

            Case sender.Name.Substring(3) = "Dispo"
                TlpDispoEmp.Visible = Not TlpDispoEmp.Visible

            Case sender.Name.Substring(3) = "Conge"
                TLPConge.Visible = Not TLPConge.Visible

            Case sender.Name.Substring(3) = "Interet"
                TLPInterets.Visible = Not TLPInterets.Visible

            Case sender.Name.Substring(3) = "Supp"
                PanSupp.Visible = Not PanSupp.Visible
        End Select


    End Sub

    Public Sub onglets(ByVal mode As Boolean)
        BtnTelephone.ImageIndex = IIf(mode, 0, 1)
        BtnInfoConnection.ImageIndex = IIf(mode, 0, 1)
        BtnIntervenant.ImageIndex = IIf(mode, 0, 1)
        BtnDispo.ImageIndex = IIf(mode, 0, 1)
        BtnConge.ImageIndex = IIf(mode, 0, 1)
        BtnSupp.ImageIndex = IIf(mode, 0, 1)
        LblInteret.ImageIndex = IIf(mode, 0, 1)
        BtnSupp.ImageIndex = IIf(mode, 0, 1)
        UcTelephone1.Visible = mode
        TLPInfoConnection.Visible = mode
        TLPDetailIntervenant.Visible = mode
        TlpDispoEmp.Visible = mode
        TLPConge.Visible = mode
        TLPInterets.Visible = mode
        PanSupp.Visible = mode
    End Sub

    Private Sub UpdateListeAffinite()
        'Liste interets
        LstInterets.Items.Clear()
        For Each a In listeAffinite
            Dim inte As New ListViewItem
            inte.Text = a.Affinite1.Nom
            inte.SubItems.Add(a.ID)
            LstInterets.Items.Add(inte)
        Next
    End Sub

    Private Sub UpdateListeFormation()
        LvFormation.Items.Clear()
        For Each a In listeFormation
            Dim inte As New ListViewItem
            inte.Text = a.Formation1.Nom
            inte.SubItems.Add(a.ID)
            LvFormation.Items.Add(inte)
        Next
    End Sub

    'Permet l'ajout, la suppression, et la consultation des intérêts
    Private Sub GestionInteret(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAInterets.Click, BtnEInterets.Click
        Select Case sender.name
            Case "BtnAInterets"
                If Not CboInterets.Text = String.Empty Then
                    Dim nouveauAff As Boolean = False

                    If CboInterets.SelectedIndex = -1 Then
                        If (From x In bd.Affinites Where x.Nom.ToLower() = CboInterets.Text.ToLower() Select x).Count > 0 Then
                            Exit Select
                        End If
                        Using nbd As New BDCarpeDiemDataContext
                            Dim nAff As New Affinite()
                            nAff.Nom = CboInterets.Text
                            nbd.Affinites.InsertOnSubmit(nAff)
                            nbd.SubmitChanges()
                        End Using
                        nouveauAff = True
                    End If
                    Dim aff As Affinite = (From x In bd.Affinites Where x.Nom.ToLower() = CboInterets.Text.ToLower() Select x).First

                    For Each Inte In LstInterets.Items
                        If Inte.Text.ToLower() = CboInterets.Text.ToLower() Then Exit Select
                    Next
                    Dim nEmpAff As New EmployeAffinite()
                    nEmpAff.Affinite1 = aff

                    listeAffinite.Add(nEmpAff)
                    UpdateListeAffinite()
                    detecterChangement(True, Nothing)
                    CboInterets.Text = ""
                    If nouveauAff Then
                        RechargerAffinite()
                    End If
                End If
            Case "BtnEInterets"
                If LstInterets.SelectedIndices.Count > 0 Then
                    detecterChangement(True, Nothing)

                    listeAffinite.RemoveAt(LstInterets.SelectedIndices(0))
                    UpdateListeAffinite()
                End If

        End Select
    End Sub

    Private Sub GestionFormation(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtAjouteFormation.Click, BtEnleverFormation.Click
        If Not IsNothing(employe) Then
            Select Case sender.name
                Case "BtAjouteFormation"
                    If Not CBFormation.Text = String.Empty Then
                        If CBFormation.SelectedIndex = -1 Then
                            Using nbd As New BDCarpeDiemDataContext
                                Dim nForm As New Formation()
                                nForm.Nom = CBFormation.Text
                                nbd.Formations.InsertOnSubmit(nForm)
                                nbd.SubmitChanges()
                            End Using
                        End If
                        Dim form As Formation = (From x In bd.Formations Where x.Nom = CBFormation.Text Select x).First

                        For Each forma In LvFormation.Items
                            If forma.Text = CBFormation.Text Then Exit Select
                        Next
                        Dim nEmpform As New EmployeFormation()
                        nEmpform.Formation1 = form

                        listeFormation.Add(nEmpform)
                        UpdateListeFormation()
                        detecterChangement(True, Nothing)
                        CBFormation.Text = ""
                    End If
                Case "BtEnleverFormation"
                    If LvFormation.SelectedIndices.Count > 0 Then
                        detecterChangement(True, Nothing)

                        listeFormation.RemoveAt(LvFormation.SelectedIndices(0))
                        UpdateListeFormation()
                    End If

            End Select
        Else

        End If
    End Sub

    Public Sub chargerEmploye(ByVal emp As Integer)
        employe = (From X In bd.Employes Where X.ID = emp Select X).First
        ErrVal.Clear()
        afficherEmploye()
        gererDroits()
    End Sub

    Public Sub afficherEmploye()
        prog = True
        changerMode(mode.consultation)

        With employe
            TxtNom.Text = .Nom
            TxtPrenom.Text = .Prenom
            TxtNAS.Text = .NAS
            If .Poste = 4 Then .Poste = 3
            CboPoste.SelectedIndex = .Poste
            ImgEmploye.BackgroundImage = Nothing
            'photo
            If Not IsNothing(.Photo) Then
                Dim flux As New IO.MemoryStream(.Photo.ToArray, 0, .Photo.Length)
                ImgEmploye.BackgroundImage = Image.FromStream(flux, True)
            Else
                ImgEmploye.BackgroundImage = My.Resources.default_photo
            End If

            If Not IsNothing(.DateNaissance) Then DtpDateNaissance.Value = .DateNaissance
            TxtAdresse.Text = .Adresse
            If Not IsNothing(.Ville) Then CboVille.SelectedValue = .Ville
            TxtCodePostal.Text = .CodePostal
            TxtCourriel.Text = .Courriel
            TxtNotes.Text = .Note

            TxtUtilsateur.Text = .Login
            TxtMotdePasse.Text = String.Empty
            If Not IsNothing(.GestionBeneficiaire) Then CboBeneficiaires.SelectedIndex = .GestionBeneficiaire Else CboBeneficiaires.SelectedIndex = 0
            If Not IsNothing(.GestionEmploye) Then CboEmployes.SelectedIndex = .GestionEmploye Else CboEmployes.SelectedIndex = 0
            If Not IsNothing(.GestionHoraire) Then CboHoraires.SelectedIndex = .GestionHoraire Else CboHoraires.SelectedIndex = 0
            If Not IsNothing(.DateEmbauche) Then DtpDebut.Value = .DateEmbauche Else DtpDebut.Text = ""
            If Not IsNothing(.DateFin) Then DtpFin.Value = .DateFin : DtpFin.Checked = True Else DtpFin.Checked = False

            listeFormation = .EmployeFormations.ToList()
            listeConge = .Conges.OrderBy(Function(x) x.DateFin).ToList()
            UcTelephone1.SetTelephones(.Telephones.ToList())
            listeAffinite = .EmployeAffinites.ToList()
            UpdateListConge()
            UpdateListeAffinite()
            UpdateListeFormation()

            UcDispoEmploye1.Disponibilite.Clear()
            For Each disp In .Disponibilites
                Dim dispo As New DispoEmp
                dispo.HeureDebut = disp.HeureDebut.ToString
                dispo.HeureFin = (disp.HeureDebut + disp.Duree).ToString
                dispo.Jour = disp.Jour
                UcDispoEmploye1.Disponibilite.Add(dispo)
            Next
            UcDispoEmploye1.RefreshDispo()

        End With
        Select Case CboPoste.SelectedIndex
            Case 0
                inter.afficherEmploye(employe.ID)
            Case 1
                bure.afficherEmploye(employe.ID)
            Case 2
                stage.afficherEmploye(employe.ID)
        End Select
        changerMode(mode.consultation)
        RaiseEvent modification(False, Nothing)
        prog = False
    End Sub

    Private Function verifierFormation(ByVal formation As String, ByVal liste() As DAL.Formation)

        For i = 0 To liste.Count - 1
            If liste(i).Nom = formation Then Return True
        Next
        Return False
    End Function

    Private Function verifierFormation(ByVal formation As String, ByVal liste() As String)

        For i = 0 To liste.Count - 1
            If liste(i) = formation Then Return True
        Next
        Return False
    End Function

    Public Function verifierTelephone(ByVal telephone As Integer, ByVal liste() As DAL.Telephone)

        For i = 0 To liste.Count - 1
            If liste(i).ID = telephone Then Return True
        Next
        Return False
    End Function

    Public Function verifierConge(ByVal Conge As Integer, ByVal liste() As DAL.Conge)
        For i = 0 To liste.Count - 1
            If liste(i).ID = Conge Then Return True
        Next
        Return False
    End Function

    Public Function verifierConge(ByVal conge As Integer, ByVal liste As List(Of Conge))

        For i = 0 To liste.Count - 1
            If IsDBNull(liste(i).id) Then Continue For
            If liste(i).id = conge Then Return True
        Next
        Return False
    End Function

    Public Sub changerMode(ByVal nmode As Integer)
        Static aMode As Mode = CarpeDiemHoraire.Mode.ajout

        Select Case aMode
            Case CarpeDiemHoraire.Mode.ajout

            Case CarpeDiemHoraire.Mode.edition

            Case CarpeDiemHoraire.Mode.consultation
        End Select

        Select Case nmode
            Case CarpeDiemHoraire.Mode.ajout
                RaiseEvent suppression(False, Nothing)
            Case CarpeDiemHoraire.Mode.edition

            Case CarpeDiemHoraire.Mode.consultation
                RaiseEvent modification(False, Nothing)
                RaiseEvent annulation(False, Nothing)

        End Select

        aMode = mode
        mode = nmode
    End Sub

    'Permet de détecter les changements dans les zones de texte (Textbox, DateTimePicker, Combobox...), radio, check
    'Ne détecte pas les , liste
    Private Sub detecterChangement(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNom.TextChanged, TxtPrenom.TextChanged,
        TxtNAS.TextChanged, DtpDateNaissance.ValueChanged, TxtAdresse.TextChanged, CboVille.TextChanged, TxtCodePostal.TextChanged, TxtCourriel.TextChanged,
        TxtNotes.TextChanged, TxtUtilsateur.TextChanged, TxtMotdePasse.TextChanged, DtpDebut.ValueChanged, DtpFin.ValueChanged,
        BtnAInterets.Click, BtnEInterets.Click, CboPoste.SelectedIndexChanged, CboBeneficiaires.SelectedIndexChanged, CboEmployes.SelectedIndexChanged, CboHoraires.SelectedIndexChanged
        If prog Then Exit Sub
        If TypeOf (sender) Is Boolean AndAlso sender = True Then
            RaiseEvent modification(True, Nothing)
            RaiseEvent annulation(True, Nothing)
            If mode = CarpeDiemHoraire.Mode.consultation Then changerMode(mode.edition)
            Exit Sub
        End If
        Select Case True
            Case sender.name.substring(0, 3) = "Txt" Or sender.name.substring(0, 3) = "Dtp" Or sender.name.substring(0, 3) = "Cbo"
                RaiseEvent modification(True, Nothing)
                RaiseEvent annulation(True, Nothing)
                If mode = mode.consultation Then
                    changerMode(mode.edition)
                End If
            Case sender.name.substring(0, 3) = "Rbo" Or sender.name.substring(0, 3) = "Chk"
                RaiseEvent modification(True, Nothing)
                RaiseEvent annulation(True, Nothing)
                If mode = mode.consultation Then
                    changerMode(mode.edition)
                End If
        End Select
    End Sub

    Private Sub ViderChamps()
        For Each iem In TLPMain.Controls
            If iem.GetType() Is GetType(TableLayoutPanel) Then
                For Each item In iem.Controls
                    Select Case item.GetType()
                        Case GetType(TextBox)
                            CType(item, TextBox).Text = String.Empty
                        Case GetType(DateTimePicker)
                            CType(item, DateTimePicker).Value = Date.Today
                            CType(item, DateTimePicker).Checked = False
                        Case GetType(CheckBox)
                            CType(item, CheckBox).Checked = False
                        Case GetType(RadioButton)
                            CType(item, RadioButton).Checked = False
                        Case GetType(ListView)
                            CType(item, ListView).Items.Clear()
                        Case GetType(ListBox)
                            CType(item, ListBox).Items.Clear()
                        Case GetType(PictureBox)
                            CType(item, PictureBox).BackgroundImage = My.Resources.default_photo
                    End Select
                Next
            End If
        Next
        CboHoraires.SelectedIndex = 0
        CboEmployes.SelectedIndex = 0
        CboBeneficiaires.SelectedIndex = 0
        CboPoste.SelectedIndex = 3
    End Sub

    Private Sub CboPoste_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboPoste.SelectedIndexChanged
        PanSupp.Controls.Clear()
        BtnSupp.Show()
        If Not prog Then
            PanSupp.Show()
        End If
        Select Case CboPoste.SelectedIndex
            Case 0
                BtnSupp.Text = "Intervenant"
                PanSupp.Controls.Add(inter)
                PanSupp.Height = inter.Height
            Case 1
                BtnSupp.Text = "Employé de Bureau"
                PanSupp.Controls.Add(bure)
                PanSupp.Height = bure.Height
            Case 2
                BtnSupp.Text = "Stagiaire"
                PanSupp.Controls.Add(stage)
                PanSupp.Height = stage.Height
            Case 3
                PanSupp.Hide()
                BtnSupp.Hide()
        End Select

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim villeEnCour As Ville = CboVille.SelectedItem
        Using villediag As New FrmGestionVille
            villediag.ShowDialog()
            RechargerVilles()
            If Not villeEnCour Is Nothing AndAlso CboVille.Items.Contains(villeEnCour) Then
                CboVille.SelectedItem = villeEnCour
            End If
        End Using
    End Sub

    Public Sub RechargerVilles()
        Dim listeVille As New List(Of Ville)
        For Each Ville In bd.Villes
            listeVille.Add(Ville)
        Next
        CboVille.DataSource = listeVille

    End Sub
    Public Sub RechargerAffinite()

        Dim listeAff As New List(Of Affinite)
        For Each Aff In bd.Affinites
            listeAff.Add(Aff)
        Next
        CboInterets.DataSource = listeAff
    End Sub

    Public Sub RechargerFormation()
        Dim listeForm As New List(Of Formation)
        For Each form In bd.Formations
            listeForm.Add(form)
        Next
        CBFormation.DataSource = listeForm
    End Sub

    Private Sub UcDispoEmploye1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UcDispoEmploye1.DoubleClick, BtnModDispo.Click
        If mode <> mode.ajout Then
            FrmGestionDispo.ShowDialog()

            UcDispoEmploye1.Disponibilite.Clear()
            For Each disp In employe.Disponibilites
                Dim dispo As New DispoEmp
                dispo.HeureDebut = disp.HeureDebut.ToString
                dispo.HeureFin = (disp.HeureDebut + disp.Duree).ToString
                dispo.Jour = disp.Jour
                UcDispoEmploye1.Disponibilite.Add(dispo)
            Next
            UcDispoEmploye1.RefreshDispo()
        Else
            MsgBox("Veuillez sauvegarder l'employé avant d'ajouter des disponibilité")
        End If
    End Sub

    ReadOnly Property getEmploye As Integer
        Get
            Return employe.ID
        End Get
    End Property

    Private Sub LstInterets_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstInterets.SelectedIndexChanged
        If empConnecte.gestionEmploye = 2 Then
            BtnEInterets.Enabled = IIf(LstInterets.SelectedItems.Count = 0, False, True)
        End If

    End Sub

    Private Sub ImgEmploye_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImgEmploye.DoubleClick, BtnChoisirPhoto.Click
        Dim nImage As Bitmap
        Using diag As New OpenFileDialog
            diag.Filter = "Image Files|*.png;*.bmp;*.jpg|All Files|*.*"
            If diag.ShowDialog() = DialogResult.OK Then
                Try
                    nImage = New Bitmap(diag.FileName)
                Catch ex As Exception
                    MessageBox.Show("Type de fichier inconnu ou fichier corompu.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Return
                End Try
            Else
                Return
            End If
        End Using
        Using diag As New FrmAjusterImage()
            If Not ImgEmploye.BackgroundImage Is Nothing Then
                diag.StartImage = nImage
            End If
            diag.FinalSize = New Size(ImgEmploye.Width, ImgEmploye.Height)
            If diag.ShowDialog() = DialogResult.OK Then
                ImgEmploye.BackgroundImage = diag.ResultImage
                changerMode(mode.edition)
                RaiseEvent modification(True, Nothing)
            End If
        End Using
    End Sub

    Private Sub TLP_Main_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Focus()
    End Sub

    Sub gererDroits()
        Select Case empConnecte.gestionEmploye
            Case 0
                lectureSeule(True)
            Case 1
                lectureSeule(True)
            Case 2
                lectureSeule(False)
                If employe.ID = empConnecte.id Then
                    RaiseEvent suppression(False, Nothing)
                Else
                    RaiseEvent suppression(True, Nothing)
                End If
        End Select

        '    CboBeneficiaires.Enabled = False
        '    CboEmployes.Enabled = False
        '    CboHoraires.Enabled = False

    End Sub


    Private Sub lectureSeule(ByVal mode As Boolean)
        For Each iem In TLPMain.Controls
            If iem.GetType() Is GetType(TableLayoutPanel) AndAlso CType(iem, TableLayoutPanel).Name <> "TLPConge" Then
                For Each item In iem.Controls
                    Select Case item.GetType()
                        Case GetType(TextBox)
                            CType(item, TextBox).ReadOnly = mode
                            CType(item, TextBox).ForeColor = Color.Black
                            CType(item, TextBox).BackColor = Color.White
                        Case GetType(DateTimePicker)
                            CType(item, DateTimePicker).Enabled = Not mode
                        Case GetType(CheckBox)
                            CType(item, CheckBox).Enabled = Not mode
                        Case GetType(RadioButton)
                            CType(item, RadioButton).Enabled = Not mode
                        Case GetType(ListView)
                            CType(item, ListView).Enabled = Not mode
                        Case GetType(ListBox)
                            CType(item, ListBox).Enabled = Not mode
                        Case GetType(PictureBox)
                            CType(item, PictureBox).Enabled = Not mode
                        Case GetType(ComboBox)
                            CType(item, ComboBox).Enabled = Not mode
                    End Select
                Next
            End If
        Next
        BtnAjouterConge.Enabled = Not mode
        BtnAInterets.Enabled = Not mode
        Button1.Enabled = Not mode
        BtnChoisirPhoto.Visible = Not mode

        UcTelephone1.Lecture = mode
        UcDispoEmploye1.Enabled = Not mode
        BtnModDispo.Enabled = Not mode
        inter.lectureSeule(mode)
        bure.lectureSeule(mode)
        stage.lectureSeule(mode)
        GroupBox1.Enabled = Not mode
    End Sub

    'GESTION DES CONGÉS V2
    Private ModeEditionConge As Integer = 0 '0=lecture, 1=ajout, 2=modification
    Private IndexCongeSelection As Integer = -1
    Private Sub ToggleEditionConge(ByVal state As Integer) '0=lecture, 1=ajout, 2=modification
        ModeEditionConge = state
        If state = 1 Or state = 2 Then
            TxtRaison.Enabled = True
            DtpJourDebut.Enabled = True
            DtpJourFin.Enabled = True
            DtpHeureDebut.Enabled = True
            DtpHeureFin.Enabled = True
            TxtDetail.Enabled = True
            LvConges.Enabled = False
            CkbAllDay.Enabled = True
            BtnModifierConge.Enabled = True
            BtnSupprimerConge.Enabled = False
            BtnAjouterConge.Text = "Enregistrer"
            BtnModifierConge.Text = "Annuler"
        Else
            TxtRaison.Enabled = False
            DtpJourDebut.Enabled = False
            DtpJourFin.Enabled = False
            DtpHeureDebut.Enabled = False
            DtpHeureFin.Enabled = False
            TxtDetail.Enabled = False
            LvConges.Enabled = True
            CkbAllDay.Enabled = False
            BtnModifierConge.Enabled = (LvConges.SelectedItems.Count = 1)
            BtnAjouterConge.Text = "Ajouter"
            BtnModifierConge.Text = "Modifier"
        End If
    End Sub

    Private Sub ViderEditionConge()
        ChangementDynamique = True
        TxtRaison.Text = String.Empty
        DtpJourDebut.Value = Date.Today
        DtpJourFin.Value = Date.Today
        DtpHeureDebut.Value = Date.Today
        DtpHeureDebut.Checked = False
        DtpHeureFin.Value = Date.Today
        DtpHeureFin.Checked = False
        CkbAllDay.Checked = True
        TxtDetail.Text = String.Empty
        ChangementDynamique = False
    End Sub

    Private Sub UpdateListConge()
        LvConges.Items.Clear()
        For Each cong In listeConge
            Dim itm As New ListViewItem(cong.Titre)
            If cong.ToutJournee Then

            End If
            itm.SubItems.Add(cong.DateDebut)
            itm.Tag = cong.ID
            LvConges.Items.Add(itm)
        Next
    End Sub

    Private Sub AfficherConge(ByVal cong As DAL.Conge)
        ChangementDynamique = True
        Dim dDeb, dFin As Date
        dDeb = cong.DateDebut.Value
        dFin = cong.DateFin.Value
        DtpJourDebut.Value = New Date(dDeb.Year, dDeb.Month, dDeb.Day)
        DtpJourFin.Value = New Date(dFin.Year, dFin.Month, dFin.Day)
        CkbAllDay.Checked = cong.ToutJournee
        If DtpJourDebut.Value <> dDeb Or DtpJourFin.Value <> dFin Then 'Detecte si des heures on été entrées
            DtpHeureDebut.Checked = True
            DtpHeureDebut.Value = Date.Today.AddHours(dDeb.Hour)
            DtpHeureDebut.Value = DtpHeureDebut.Value.AddMinutes(dDeb.Minute)
            DtpHeureFin.Checked = True
            DtpHeureFin.Value = Date.Today.AddHours(dFin.Hour)
            DtpHeureFin.Value = DtpHeureFin.Value.AddMinutes(dFin.Minute)
            CkbAllDay.Checked = False
        Else
            DtpHeureDebut.Checked = False
            DtpHeureFin.Checked = False
        End If

        TxtRaison.Text = cong.Titre
        TxtDetail.Text = cong.Description
        ChangementDynamique = False
    End Sub

    Private Sub BtnAjouterConge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAjouterConge.Click
        If BtnAjouterConge.Text = "Ajouter" Then
            ViderEditionConge()
            ToggleEditionConge(1)
        Else 'Enregistrer
            ErrVal.Clear()
            If TxtRaison.Text = String.Empty Then
                ErrVal.SetError(TxtRaison, "Le titre ne doit pas être vide")
                Return
            End If
            Dim cong As DAL.Conge
            If ModeEditionConge = 1 Then 'Ajout
                cong = New DAL.Conge
            Else 'Modification
                If IndexCongeSelection = -1 Then 'Aucun congé selectionné
                    ViderEditionConge()
                    ToggleEditionConge(0)
                    Return
                End If
                cong = listeConge(IndexCongeSelection)

            End If
            If DtpJourDebut.Value < Today Then
                If Not MsgBox("La date de début est passé voulez vous l'enregistrer quand même", vbYesNo, vbNo) = 6 Then
                    Return
                End If
            End If
            If DtpHeureDebut.Checked Or DtpHeureFin.Checked Then
                Dim dtpHD, dtpHF, datedebut, datefin As Date
                dtpHD = DtpHeureDebut.Value
                dtpHF = DtpHeureFin.Value
                datedebut = DtpJourDebut.Value.AddHours(dtpHD.Hour)
                datedebut = cong.DateDebut.Value.AddMinutes(dtpHD.Minute)
                datefin = DtpJourFin.Value.AddHours(dtpHF.Hour)
                datefin = cong.DateFin.Value.AddMinutes(dtpHF.Minute)
                If Not datedebut <= datefin Then
                    ErrVal.SetError(DtpJourDebut, "La date de fin doit être après la date de début")
                    ErrVal.SetError(DtpJourFin, "La date de fin doit être après la date de début")
                    Return
                End If
                cong.DateDebut = datedebut
                cong.DateFin = datefin
            Else
                If Not DtpJourDebut.Value <= DtpJourFin.Value Then
                    ErrVal.SetError(DtpJourDebut, "La date de fin doit être après la date de début")
                    ErrVal.SetError(DtpJourFin, "La date de fin doit être après la date de début")
                    Return
                End If
                cong.DateDebut = DtpJourDebut.Value
                cong.DateFin = DtpJourFin.Value
            End If

            cong.ToutJournee = CkbAllDay.Checked
            cong.Titre = TxtRaison.Text
            cong.Description = TxtDetail.Text
            If ModeEditionConge = 1 Then 'Ajout
                listeConge.Add(cong)
            Else 'Modification
                listeConge(IndexCongeSelection) = cong
            End If

            ToggleEditionConge(0)

            UpdateListConge()
            RaiseEvent modification(True, Nothing)
        End If
    End Sub

    Private Sub BtnModifierConge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModifierConge.Click
        If BtnModifierConge.Text = "Modifier" Then
            If IndexCongeSelection = -1 Then 'Aucun congé selectionné
                Return
            End If
            AfficherConge(listeConge(LvConges.SelectedIndices(0)))
            ToggleEditionConge(2)
        Else 'Annuler
            ViderEditionConge()
            'TO-DO: reselectionner le dernier congé dans la liste
            ToggleEditionConge(0)
        End If
    End Sub

    Private Sub BtnSupprimerConge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSupprimerConge.Click
        If IndexCongeSelection = -1 Then 'Aucun congé selectionné
            Return
        Else
            If MessageBox.Show("Voulez-vous vraiment supprimer ce congé?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
                listeConge.RemoveAt(IndexCongeSelection)
                IndexCongeSelection = -1
                ViderEditionConge()
                UpdateListConge()
                RaiseEvent modification(True, Nothing)
            End If
        End If

    End Sub

    Private Sub LvConges_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LvConges.SelectedIndexChanged

        If LvConges.SelectedItems.Count = 1 Then
            IndexCongeSelection = LvConges.SelectedIndices(0)
            AfficherConge(listeConge(LvConges.SelectedIndices(0)))
        Else
            IndexCongeSelection = -1
            ViderEditionConge()
        End If
        If empConnecte.gestionEmploye = 2 Then
            BtnModifierConge.Enabled = (IndexCongeSelection <> -1)
            BtnSupprimerConge.Enabled = (IndexCongeSelection <> -1)
        End If

    End Sub
    Private ChangementDynamique As Boolean = False
    Private Sub CongesCkb_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CkbAllDay.CheckedChanged, DtpHeureDebut.ValueChanged, DtpHeureFin.ValueChanged
        If Not ChangementDynamique Then
            If sender.Equals(CkbAllDay) Then
                ChangementDynamique = True
                If CType(sender, CheckBox).Checked = True Then
                    DtpHeureDebut.Checked = False
                    DtpHeureFin.Checked = False
                Else
                    DtpHeureDebut.Checked = True
                    DtpHeureFin.Checked = True
                End If
                ChangementDynamique = False
            ElseIf sender.Equals(DtpHeureDebut) Or sender.Equals(DtpHeureFin) Then
                ChangementDynamique = True
                If CType(sender, DateTimePicker).Checked = True Then
                    CkbAllDay.Checked = False
                    DtpHeureDebut.Checked = True
                    DtpHeureFin.Checked = True
                Else
                    CkbAllDay.Checked = True
                    DtpHeureDebut.Checked = False
                    DtpHeureFin.Checked = False
                End If
                ChangementDynamique = False
            End If
        End If

    End Sub

    Private Sub LvFormation_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LvFormation.SelectedIndexChanged
        If empConnecte.gestionEmploye = 2 Then
            BtEnleverFormation.Enabled = (LvFormation.SelectedItems.Count = 1)
        End If

    End Sub
End Class

Public Enum Mode
    ajout = 1
    edition = 2
    consultation = 3
End Enum

Public Class Conge
    Public titre, description As String
    Public ddebut, dfin As Date
    Public hdebut, hfin As Date
    Public heures As Boolean
    Public id As Integer

    Sub New()
        ddebut = Now
        dfin = Now
        hdebut = Now
        hfin = Now
        heures = 0
        id = -1

    End Sub

End Class